//
//  SortTableViewCell.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/27.
//

#import "SortTableViewCell.h"
#import "CommonUtil.h"
@interface SortTableViewCell()

@property (strong, nonatomic) UILabel * indexLabel;
@property (strong, nonatomic) UIView * whiteView;
@property (strong, nonatomic) UIView * line1;
@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UILabel * nameLabel;
@property (strong, nonatomic) UILabel * numberLabel;
@property (strong, nonatomic) UILabel * valueLabel;
@property (strong, nonatomic) UIButton * followBtn;
@end

@implementation SortTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor =  RGB(243.0, 243.0, 243.0);
        [self.contentView addSubview:self.whiteView];
        [self.whiteView addSubview:self.indexLabel];
        [self.whiteView addSubview:self.nameLabel];
        [self.whiteView addSubview:self.iconImageView];
        [self.whiteView addSubview:self.numberLabel];
        [self.whiteView addSubview:self.valueLabel];
        [self.whiteView addSubview:self.followBtn];
        [self.whiteView addSubview:self.line1];
    }
    return self;
}

-(void)setModel:(SortModel *)model{
    _model = model;
    self.indexLabel.text = [NSString stringWithFormat:@"%zd",model.sortIndex+1];
    self.nameLabel.text = @"王刚";
    self.numberLabel.text = @"16700";
    self.valueLabel.text = @"成长值";
    
}


-(void)layoutSubviews{
    [super layoutSubviews];
    self.whiteView.height = self.height;
    self.indexLabel.height = self.height;
    self.line1.width = self.whiteView.width - AD(40);
    self.line1.bottom = self.height-AD(0.5);
    
    self.iconImageView.centerY = self.height/2;
    self.iconImageView.left = self.indexLabel.right+AD(3);
    
    self.nameLabel.top = self.iconImageView.top;
    self.nameLabel.left = self.iconImageView.right + AD(10);
    
    [self.numberLabel sizeToFit];
    self.numberLabel.left = self.nameLabel.left;
    self.numberLabel.bottom = self.iconImageView.bottom;
    
    self.valueLabel.left = self.numberLabel.right + AD(5);
    self.valueLabel.bottom = self.iconImageView.bottom;
    
    self.followBtn.centerY = self.iconImageView.centerY;
    self.followBtn.right = self.whiteView.width - AD(30);
}


- (void)followBtnClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected) {
        [sender setTitle:@"取消关注" forState:UIControlStateNormal];
        sender.backgroundColor = [UIColor lightGrayColor];
    }else{
        [sender setTitle:@"+关注" forState:UIControlStateNormal];
        sender.backgroundColor = RGB(255.0, 90.0, 117.0);
    }
}



-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(AD(10), 0, SCREEN_WIDTH-AD(20), 0)];
        _whiteView.backgroundColor = [UIColor whiteColor];
    }
    return _whiteView;
}

-(UILabel *)indexLabel{
    if (!_indexLabel) {
        _indexLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, AD(30), 0)];
        _indexLabel.font = [UIFont systemFontOfSize:AD(18)];
        _indexLabel.textColor = [UIColor blackColor];
        _indexLabel.textAlignment = NSTextAlignmentRight;
    }
    return _indexLabel;
}

-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        CGFloat w = AD(55);
        _iconImageView.frame = CGRectMake(0,0, w, w);
        _iconImageView.layer.cornerRadius = w/2;
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}


-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , AD(100), AD(25))];
        _nameLabel.font = [UIFont systemFontOfSize:AD(19)];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.text = @"吴妍珠";
    }
    return _nameLabel;
}
-(UILabel *)numberLabel{
    if (!_numberLabel) {
        _numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , 0, AD(25))];
        _numberLabel.font = [UIFont systemFontOfSize:AD(18)];
        _numberLabel.textColor = RGB(255.0, 90.0, 117.0);
    }
    return _numberLabel;
}

-(UILabel *)valueLabel{
    if (!_valueLabel) {
        _valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0 , AD(80), AD(20))];
        _valueLabel.font = [UIFont systemFontOfSize:AD(13)];
        _valueLabel.textColor = [UIColor lightGrayColor];
        _valueLabel.text = @"成长值";
    }
    return _valueLabel;
}

-(UIButton *)followBtn{
    if (!_followBtn) {
        _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followBtn setTitle:@"+关注" forState:UIControlStateNormal];
        _followBtn.backgroundColor = RGB(255.0, 90.0, 117.0);
        [_followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_followBtn addTarget:self action:@selector(followBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _followBtn.layer.cornerRadius = AD(5);
        _followBtn.clipsToBounds = YES;
        
        _followBtn.frame = CGRectMake(0, 0, AD(80), AD(30));
        _followBtn.titleLabel.font = [UIFont systemFontOfSize:AD(14)];
    }
    return _followBtn;
}

-(UIView *)line1{
    if (!_line1) {
        _line1 = [[UIView alloc] initWithFrame:CGRectMake(AD(40), 0, 0, AD(0.5))];
        _line1.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    }
    return _line1;
}

@end
